import React from 'react'
import { Routes, Route, Navigate } from 'react-router-dom'
import LayOut from './Layout'
import Login from './pages/Login'
import NotFound from './pages/NotFound'
import routes from './routes'
import { isLogin } from './utils'
export default function App() {
  return (
    <Routes>
      <Route path="/" element={
        isLogin()
        ?
        <LayOut/>
        :
        <Navigate to={'/login'}/>
      }>
          {
            routes.map(route => {
              return (
                <Route 
                  key={route.path} 
                  path={route.path} 
                  element={<route.component/>}/>
              )
            })
          }
          <Route path="/" element={<Navigate to="/dashBoard"/>}/>
      </Route>
      <Route path="/login" element={<Login/>}/>
      <Route path="*" element={<NotFound/>}/>
      
    </Routes>
  )
}
